package com.example.a97369.zyfupt_102zzr.model;

import com.example.a97369.zyfupt_102zzr.bean.VideoBeanAnother;
import com.example.a97369.zyfupt_102zzr.iface.VideoAnotherListener;
import com.example.a97369.zyfupt_102zzr.iface.VideoAnotheriface;
import com.example.a97369.zyfupt_102zzr.service.VideoServiceAnother;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by 97369 on 2017/5/28.
 */

public class VideoModelAnother implements VideoAnotheriface{
    private Retrofit retrofit;
    private String BASEURL="http://amicool.neusoft.edu.cn/";
    //构造函数
    public VideoModelAnother(){
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    //获取文章数据
    @Override
    public void getResultList(String video, int page, String sessionID, final VideoAnotherListener videoAnotherListener) {
        //使用Retrofit-2
        VideoServiceAnother videoService1=retrofit.create(VideoServiceAnother.class);
        Call<List<VideoBeanAnother>> call = videoService1.getResult(video,page,sessionID);
        //使用Retrofit-3
        call.enqueue(new Callback<List<VideoBeanAnother>>() {
            @Override
            public void onResponse(Call<List<VideoBeanAnother>> call, Response<List<VideoBeanAnother>> response) {
                if(response.isSuccessful()&&response!=null){
                    videoAnotherListener.onResponse(response.body());
                }
                else
                    videoAnotherListener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<List<VideoBeanAnother>> call, Throwable t) {
                videoAnotherListener.onFail(t.toString());
            }
        });
    }
}

